
#ifndef __REAL2_H__
#define __REAL2_H__

#include "FileStream.h"

class Real2
{
public:

	// Constructor
	Real2() {}
	Real2(float _u, float _v)
	{
		u = _u;
		v = _v;
	}

	// Set
	void Set(float _u, float _v)
	{
		u = _u;
		v = _v;
	}

	// Operators
	bool friend operator == (const Real2 &a, const Real2 &b)
	{ return (a.u == b.u) && (a.v == b.v); }
	Real2 friend operator + (const Real2 &a, const Real2 &b)
	{ return Real2(a.u + b.u, a.v + b.v); }
	Real2 friend operator - (const Real2 &a, const Real2 &b)
	{ return Real2(a.u - b.u, a.v - b.v); }
	Real2 friend operator * (const Real2 &a, float b)
	{ return Real2(a.u * b, a.v * b); }
	Real2 friend operator * (float b, const Real2 &a)
	{ return Real2(a.u * b, a.v * b); }

	Real2 operator += (const Real2 &a)
	{ u += a.u; v += a.v; return *this; }
	Real2 operator -= (const Real2 &a)
	{ u -= a.u; v -= a.v; return *this; }
	Real2 operator *= (float a)
	{ u *= a; v *= a; return *this; }

	// Write to a file
	void Write(FileStream &file)
	{
		if(file.IsBinary()) file.Write(((char*)&u), sizeof(Real2));
		else file.oFile << "(" << u << ", " << v << ")\n";
	}

	// Read from file
	void Read(FileStream &file)
	{
		if(file.IsBinary()) file.Read(((char*)&u), sizeof(Real2));
		//else file << "(" << u << ", " << v << ")\n";
	}

	float u;
	float v;
};

#endif // __REAL2_H__